import json

# 字典转化为json格式
"""
dict_value = {}
dict_value['name'] = 'andy'
dict_value['age'] = 18
dict_value['hobby'] = ['basketball','football','baseball']
print(dict_value)
print(type(dict_value))
json_str = json.dumps(dict_value)# 将json字典数据转换为字符串类型
print(json_str)
print(type(json_str)) # json->string

# 存储到文件中
file = open("json.txt","w")
json.dump(dict_value,file)
"""

# dumps以字符串形式展示
# dump 写入文件中使用

# 将json转化为字典
json_str = '{"name":"andy","age":18}'
result = json.loads(json_str)
print(type(result))

file = open("json.txt","r")
result = json.load(file)
print(result)

